using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;

namespace WindowsFormsDataBaice
{
    public static class UIStyleManager
    {
        // 主色调 - 医疗蓝色主题
        public static Color PrimaryColor = Color.FromArgb(52, 152, 219);
        public static Color PrimaryDarkColor = Color.FromArgb(41, 128, 185);
        public static Color PrimaryLightColor = Color.FromArgb(93, 173, 226);
        public static Color AccentColor = Color.FromArgb(46, 204, 113);
        public static Color WarningColor = Color.FromArgb(230, 126, 34);
        public static Color DangerColor = Color.FromArgb(231, 76, 60);

        // 背景色
        public static Color BackgroundColor = Color.FromArgb(248, 249, 250);
        public static Color CardBackgroundColor = Color.White;
        public static Color BorderColor = Color.FromArgb(222, 226, 230);

        // 文字颜色
        public static Color TextPrimaryColor = Color.FromArgb(33, 37, 41);
        public static Color TextSecondaryColor = Color.FromArgb(108, 117, 125);
        public static Color TextLightColor = Color.White;

        // 字体
        public static Font TitleFont = new Font("微软雅黑", 20, FontStyle.Bold);
        public static Font SubtitleFont = new Font("微软雅黑", 14, FontStyle.Bold);
        public static Font BodyFont = new Font("微软雅黑", 10);
        public static Font ButtonFont = new Font("微软雅黑", 10, FontStyle.Bold);
        public static Font SmallFont = new Font("微软雅黑", 9);

        // 按钮样式
        public static void ApplyButtonStyle(Button button, ButtonStyle style = ButtonStyle.Primary)
        {
            button.FlatStyle = FlatStyle.Flat;
            button.FlatAppearance.BorderSize = 0;
            button.Font = ButtonFont;
            button.Cursor = Cursors.Hand;

            switch (style)
            {
                case ButtonStyle.Primary:
                    button.BackColor = PrimaryColor;
                    button.ForeColor = TextLightColor;
                    button.FlatAppearance.MouseOverBackColor = PrimaryDarkColor;
                    button.FlatAppearance.MouseDownBackColor = Color.FromArgb(31, 97, 141);
                    break;
                case ButtonStyle.Secondary:
                    button.BackColor = Color.Transparent;
                    button.ForeColor = PrimaryColor;
                    button.FlatAppearance.BorderColor = PrimaryColor;
                    button.FlatAppearance.BorderSize = 1;
                    button.FlatAppearance.MouseOverBackColor = Color.FromArgb(240, 248, 255);
                    button.FlatAppearance.MouseDownBackColor = Color.FromArgb(230, 240, 250);
                    break;
                case ButtonStyle.Success:
                    button.BackColor = AccentColor;
                    button.ForeColor = TextLightColor;
                    button.FlatAppearance.MouseOverBackColor = Color.FromArgb(39, 174, 96);
                    button.FlatAppearance.MouseDownBackColor = Color.FromArgb(27, 122, 67);
                    break;
                case ButtonStyle.Warning:
                    button.BackColor = WarningColor;
                    button.ForeColor = TextLightColor;
                    button.FlatAppearance.MouseOverBackColor = Color.FromArgb(211, 84, 0);
                    button.FlatAppearance.MouseDownBackColor = Color.FromArgb(148, 59, 0);
                    break;
                case ButtonStyle.Danger:
                    button.BackColor = DangerColor;
                    button.ForeColor = TextLightColor;
                    button.FlatAppearance.MouseOverBackColor = Color.FromArgb(192, 57, 43);
                    button.FlatAppearance.MouseDownBackColor = Color.FromArgb(134, 40, 30);
                    break;
            }
        }

        // 面板样式
        public static void ApplyPanelStyle(Panel panel, PanelStyle style = PanelStyle.Card)
        {
            switch (style)
            {
                case PanelStyle.Card:
                    panel.BackColor = CardBackgroundColor;
                    panel.BorderStyle = BorderStyle.FixedSingle;
                    break;
                case PanelStyle.Header:
                    panel.BackColor = PrimaryColor;
                    break;
                case PanelStyle.Navigation:
                    panel.BackColor = PrimaryDarkColor;
                    break;
                case PanelStyle.Content:
                    panel.BackColor = BackgroundColor;
                    break;
            }
        }

        // 标签样式
        public static void ApplyLabelStyle(Label label, LabelStyle style = LabelStyle.Body)
        {
            switch (style)
            {
                case LabelStyle.Title:
                    label.Font = TitleFont;
                    label.ForeColor = TextPrimaryColor;
                    break;
                case LabelStyle.Subtitle:
                    label.Font = SubtitleFont;
                    label.ForeColor = PrimaryColor;
                    break;
                case LabelStyle.Body:
                    label.Font = BodyFont;
                    label.ForeColor = TextPrimaryColor;
                    break;
                case LabelStyle.Caption:
                    label.Font = SmallFont;
                    label.ForeColor = TextSecondaryColor;
                    break;
                case LabelStyle.Header:
                    label.Font = SubtitleFont;
                    label.ForeColor = TextLightColor;
                    break;
            }
        }

        // 文本框样式
        public static void ApplyTextBoxStyle(TextBox textBox)
        {
            textBox.Font = BodyFont;
            textBox.BorderStyle = BorderStyle.FixedSingle;
            textBox.BackColor = CardBackgroundColor;
            textBox.ForeColor = TextPrimaryColor;
        }

        // 复选框样式
        public static void ApplyCheckBoxStyle(CheckBox checkBox)
        {
            checkBox.Font = BodyFont;
            checkBox.ForeColor = TextPrimaryColor;
            checkBox.BackColor = Color.Transparent;
        }

        // 创建图标按钮
        public static Button CreateIconButton(string text, string iconText, int width = 150, int height = 120)
        {
            Button button = new Button
            {
                Text = $"{iconText}\n{text}",
                Size = new Size(width, height),
                BackColor = PrimaryColor,
                ForeColor = TextLightColor,
                FlatStyle = FlatStyle.Flat,
                Font = new Font("微软雅黑", 12, FontStyle.Bold),
                TextAlign = ContentAlignment.MiddleCenter,
                UseVisualStyleBackColor = false
            };

            ApplyButtonStyle(button, ButtonStyle.Primary);
            return button;
        }

        // 创建卡片面板
        public static Panel CreateCardPanel(string title = "", int width = 300, int height = 200)
        {
            Panel panel = new Panel
            {
                Size = new Size(width, height),
                BackColor = CardBackgroundColor,
                BorderStyle = BorderStyle.FixedSingle
            };

            if (!string.IsNullOrEmpty(title))
            {
                Label titleLabel = new Label
                {
                    Text = title,
                    Font = SubtitleFont,
                    ForeColor = PrimaryColor,
                    AutoSize = true,
                    Location = new Point(10, 10)
                };
                panel.Controls.Add(titleLabel);
            }

            return panel;
        }

        // 创建渐变背景
        public static void ApplyGradientBackground(Control control, Color startColor, Color endColor)
        {
            control.Paint += (sender, e) =>
            {
                using (LinearGradientBrush brush = new LinearGradientBrush(
                    control.ClientRectangle, startColor, endColor, LinearGradientMode.Vertical))
                {
                    e.Graphics.FillRectangle(brush, control.ClientRectangle);
                }
            };
        }
    }

    public enum ButtonStyle
    {
        Primary,
        Secondary,
        Success,
        Warning,
        Danger
    }

    public enum PanelStyle
    {
        Card,
        Header,
        Navigation,
        Content
    }

    public enum LabelStyle
    {
        Title,
        Subtitle,
        Body,
        Caption,
        Header
    }
} 